DAY2:String ends with?


Posted by birdbirdmurmur on 2023-07-15

題目連結:

解題過程:

  • 第一個想法是直接用includes(),以為可以輕鬆通過
    • 原以為includes()無法判斷string
      • 有想過要不要先判斷型態
    • 被自己笨死,看錯題目(請好好練英文x
  • 搞懂題目之後,翻開MDN字典
    • 使用endsWith()可快速判斷字串的結尾
      • 可以區分大小寫
  • Done.

解法:

function solution(str, ending){
  return str.endsWith(ending);
}

參考資料:


#javascript #Codewars #endWith







Related Posts

Python decorator

Python decorator

PHP & MySQL 陽春留言板實作

PHP & MySQL 陽春留言板實作

nmapAutomator - OSCP考試好用的工具

nmapAutomator - OSCP考試好用的工具


Comments